define(['jquery', 'text!../../Content/spaceOwners/spaceOwners.html', 'common', 'knockout'], function($, html, common, ko){

	var container;

	function init(c){
		container = $(c);
		container.html(html);
		loadTeamNav();

		$(container).on('click', '.listSupporting', function(e) {
			e.preventDefault();
			var $supportingOwnersUl = $(this).next('li').find('div');
			$supportingOwnersUl.toggleClass("hide");
		});
	}

	var viewModel = {
		SpaceOwners : ko.observable()
	};

	function loadTeamNav(){
		common.service('spaceOwners.json').success(function(data){
			var info = processData(data);
			viewModel.SpaceOwners = info;
			ko.applyBindings(viewModel, container[0]);
		});
	}
		function processData(rawData){
		var info = [];

		for(var i = 0; i < rawData.length; i++){

			var node =  {
				"NameOwner" : rawData[i].NameOwner,
				"Status" : rawData[i].Status,
				"Url" : rawData[i].Url,
				"SupportingOwners" : rawData[i].SupportingOwners,
				"Count" : (rawData[i].SupportingOwners && $.isArray(rawData[i].SupportingOwners)) ? rawData[i].SupportingOwners.length : 0
			};
			info.push(node);
		}
		return info;
	}
	return {
		"init" : init
	};

});